use "allstudies_wto2.dta", clear 

* Dropping the ordered and multinomial models, since we won't me able to FE them anyways.
drop if method_orig == "mlogit"
drop if method_orig == "ologit"
* One study, Vreeland, had a model with and without clogit/FE.  To avoid duplications, we're dropping the clogit one
drop if pval_gatt_orig!=. & pval_gatt_noth==.

* Sorting the replications and numbering them, according to the baseline replication p values
sort pval_gatt_orig
gen id = _n

* Rename
rename pval_match pval_gatt_match


*** "Descriptives of false positives"
*	Section in the paper, right after the first figure, which gives a lot of summary information
foreach var in pval_gatt_orig pval_gatt_noth pval_gatt_time pval_gatt_fe {
	di "`var'"
	gen sig_`var' = `var'<=0.10
	replace sig_`var' = . if `var'==.
	di "The percent of false positives for `var'"
	su sig_`var'
	tab sig_`var'
	di "The number of studies for `var'"
	codebook study if `var'!=.
	}
*
foreach var in pval_gatt_ct pval_gatt_fet pval_gatt_yfe pval_gatt_cyfe pval_gatt_match {
	di "`var'"
	gen sig_`var' = `var'<=0.10
	replace sig_`var' = . if `var'==.
	su sig_`var'
	codebook study if `var'!=.
	}
*
* Which studies had at least one FP?
bysort study: egen anyFP = max(sig_pval_gatt_orig)
preserve
duplicates drop study, force
tab anyFP
restore
* Which DV's had at least one FP?
bysort dv_orig: egen anyFP_DV = max(sig_pval_gatt_orig)
preserve
duplicates drop dv_orig, force
tab anyFP_DV
restore
* Limited and continuous DVs?
	* Marker for LDV models
gen ldv = 0
replace ldv = 1 if method_orig == "clogit" | method_orig == "logit" | method_orig == "probit" | method_orig == "relogit" | method_orig == "xtlogit" | method_orig == "xtnbreg" | method_orig == "xtpqml"
tab sig_pval_gatt_orig if ldv==0
tab sig_pval_gatt_orig if ldv==1



* Figure 1: GATT FP's, original replications
* First, find where the vertical line needs to be
tab  sig_pval_gatt_orig
su  pval_gatt_orig if pval_gatt_orig <0.10
su  pval_gatt_orig if pval_gatt_orig <0.05
su  pval_gatt_orig if pval_gatt_orig <0.01
* There are 32/94 signficant
twoway scatter  pval_gatt_orig id if pval_gatt_orig<.10 , xline(32.5) yline(.099) msym(Oh) xtitle("Replication #") ytitle("GATT / WTO p-value") ||  scatter  pval_gatt_orig id if pval_gatt_orig>=.10 , msym(X) xlabel(0(10)100) legend(label(1 "Sig. Result") label(2 "Insig. Result"))
*text( .2 24 "WTO Stops torture" , size(vsmall))
	graph export "reps_gatt_orig_rr.eps", as(eps) preview(off) replace




* Marker for whether the study had CFE, splines, YFE, etc
gen sameas = 0
replace sameas = 1 if  b_gatt_orig == b_gatt_noth
replace sameas = 2 if  b_gatt_orig == b_gatt_fe
replace sameas = 3 if  b_gatt_orig == b_gatt_time
replace sameas = 4 if  b_gatt_orig == b_gatt_fet
replace sameas = 5 if  b_gatt_orig == b_gatt_ct
replace sameas = 6 if  b_gatt_orig == b_gatt_yfe
replace sameas = 7 if  b_gatt_orig == b_gatt_cyfe

* Country FE?
tab sameas if sameas==2 | sameas==4 | sameas==7
* Time based fix?
tab sameas if sameas==3 | sameas==4 | sameas==5 | sameas==6 | sameas==7
* Combo of fixes?
tab sameas if sameas==4 | sameas==7


* Table 1: FP Rates across Orig, Reduced, Country FE, Splines/Trend, Matching
foreach var in pval_gatt_orig pval_gatt_noth pval_gatt_fe pval_gatt_time pval_gatt_match {
	di "The percent of false positives for `var'"
	su sig_`var'
	tab sig_`var'
	di "The number of studies for `var'"
	codebook study if `var'!=.
	}
* 



* Figure 2: GATT FP's, CFE replications
su  pval_gatt_fe if pval_gatt_fe <0.10
twoway scatter  pval_gatt_fe id if pval_gatt_fe<=.10 , xline(32.5) yline(.099) msym(Oh) xtitle("Replication #") ytitle("GATT / WTO p-value") ||  scatter  pval_gatt_fe id if pval_gatt_fe>.10 , msym(X) xlabel(0(10)90)  legend(label(1 "Sig. Result") label(2 "Insig. Result"))
	graph export "reps_gatt_fe_rr.eps", as(eps) preview(off) replace


* Figure 3: Matching replications
twoway scatter  pval_gatt_match id if sig_pval_gatt_match==1, xline(32.5) yline(0.099) msym(Oh) xtitle("Replication #") ytitle("GATT / WTO p-value") ||  scatter  pval_gatt_match id if sig_pval_gatt_match==0, msym(X) xlabel(0(10)90)  legend(label(1 "Sig. Result") label(2 "Insig. Result"))
*text( .2 24 "WTO Stops torture" , size(vsmall))
	graph export "reps_gatt_match_rr.eps", as(eps) preview(off) replace


* Percent reduction in bias, FP and not FP
su bias_match if sig_pval_gatt_match==1
su bias_match if sig_pval_gatt_match==0
probit sig_pval_gatt_match bias_match
logit sig_pval_gatt_match bias_match



* Table 2: FP Rates across Country Trends, CT + Country FE, YFE, CFE + YFE
foreach var in pval_gatt_ct pval_gatt_fet pval_gatt_yfe pval_gatt_cyfe {
	di "The percent of false positives for `var'"
	su sig_`var'
	tab sig_`var'
	di "The number of studies for `var'"
	codebook study if `var'!=.
	}
* 
